<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>register</title>
    <style type="text/css">
        body {
            text-align: center;
            padding: 0;
            margin: 0;
            font-size: 20px;
            background: skyblue;
        }
        label {
            width: 100px;
            display: inline-block;
        }
        input,button {
            border: 1px solid #eee;
            font-size: 20px;
        }
        button {
            margin-right: 30px;
        }
        div {
            margin-bottom: 30px;
        }
        .wrap {
            text-align: left;
            width: 500px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <h2>后台管理系统</h2>
    <div class="wrap">
        <div>
            <label>邮 箱：</label>
            <input type="text" value="" id="user" />
        </div>
        <div>
            <label>密 码：</label>
            <input type="password" value="" id="pass" />
        </div>
        <div>
            <label>验证码：</label>
            <input type="text" value="" id="verifyCode" />
            <button onclick="getVerifyCode()">获取验证码</button>
        </div>
    </div>
    <button onclick="doRegister()">注册</button>
    <button onclick="goLogin()">登录</button>
</body>
</html>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>
function getVerifyCode() {
    const user = $('#user').val();
    const params = {
        mail: user
    };
    const url = 'http://localhost:3000/user/getVerifyCode';

    $.post(url, params, data => {
        if (!data.errno) {
            alert('get verifyCode success');
        }
        else {
            alert('get verifyCode fail');
        }
    });
}

function doRegister() {
    const user = $('#user').val();
    const pass = $('#pass').val();
    const code = $('#verifyCode').val();
    const params = {
        us: user,
        ps: pass,
        code
    };

    const url = 'http://localhost:3000/user/reg';

    $.post(url, params, data => {
        if (!data.errno) {
            window.location.href = 'http://localhost:3000/public/html/login.html';
        }
        else {
            alert('register fail');
        }
    });
}

function goLogin() {
    window.location.href = 'http://localhost:3000/public/html/login.html';
}
</script>